﻿<?xml version="1.0" encoding="utf-8"?>
<!--
        作者：          chi.zhang
        更新时间：      20141230
        用途：          生成dotNET柜台终端的protocol.xml
-->
<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="text" indent="no" encoding="utf-8" byte-order-mark="no"/>  
	<xsl:template match="/">
	<xsl:variable name="functionPD" select="document('../model/0201_FunctionsTD.xml')"/>
	<xsl:variable name="functionHS" select="document('../model/0202_FunctionsHS.xml')"/>
	<xsl:variable name="metas" select="document('../model/0101_metadataTypeDefine.xml')"/>
	<xsl:variable name="cpacks" select="document('../model/cpack.xml')"/>
	<xsl:result-document encoding="utf-8" method="text" href="./generate/client/ConnPro.xml">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;ProtocolContent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;ProtocolMaps&gt;<xsl:for-each select="$functionPD//Functions/Function">
&lt;ProtocolMap RequestID="<xsl:value-of select="@func_no"/>" TID="SSS" RequestName="<xsl:value-of select="@func_name"/>"&gt;      
        <xsl:for-each select="Request">&lt;Request&gt;<xsl:for-each select="Field">
                        <xsl:variable name="cpack" select="@cpack"/>
                        <xsl:variable name="name" select="@name"/>
                        <xsl:variable name="cpackType" select="fn:node-name($cpacks//Cpack/*[@name=$cpack])"/>                    
                &lt;Field Label="<xsl:value-of select="$metas//Metadatas/*[@typename=$name]/@label"/>" Xpack="<xsl:value-of select="lower-case(@cpack)"/>" XpackType="<xsl:choose><xsl:when test="contains(string($cpackType),'Int')">1</xsl:when><xsl:when test="contains(string($cpackType),'Long')">1</xsl:when><xsl:when test="contains(string($cpackType),'Ratio')">2</xsl:when><xsl:when test="contains(string($cpackType),'Money')">2</xsl:when><xsl:otherwise>3</xsl:otherwise></xsl:choose>" SbpField="<xsl:value-of select="@name"/>"/&gt;</xsl:for-each>
        &lt;/Request&gt;
        </xsl:for-each>
        <xsl:for-each select="Response">&lt;Response&gt;<xsl:for-each select="Field">
                        <xsl:variable name="cpack" select="@cpack"/>
                        <xsl:variable name="name" select="@name"/>
                        <xsl:variable name="cpackType" select="fn:node-name($cpacks//Cpack/*[@name=$cpack])"/>
                &lt;Field Label="<xsl:value-of select="$metas//Metadatas/*[@typename=$name]/@label"/>" Xpack="<xsl:value-of select="lower-case(@cpack)"/>" XpackType="<xsl:choose><xsl:when test="contains(string($cpackType),'Int')">1</xsl:when><xsl:when test="contains(string($cpackType),'Long')">1</xsl:when><xsl:when test="contains(string($cpackType),'Ratio')">2</xsl:when><xsl:when test="contains(string($cpackType),'Money')">2</xsl:when><xsl:otherwise>3</xsl:otherwise></xsl:choose>" SbpField="<xsl:value-of select="@name"/>"/&gt;</xsl:for-each>
        &lt;/Response&gt;</xsl:for-each>&lt;/ProtocolMap&gt;               
	</xsl:for-each>
	<xsl:for-each select="$functionHS//Functions/Function">
&lt;ProtocolMap RequestID="<xsl:value-of select="@func_no"/>" TID="SSS" RequestName="<xsl:value-of select="@func_name"/>"&gt;      
        <xsl:for-each select="Request">&lt;Request&gt;<xsl:for-each select="Field">
                        <xsl:variable name="cpack" select="@cpack"/>
                        <xsl:variable name="name" select="@name"/>
                        <xsl:variable name="cpackType" select="fn:node-name($cpacks//Cpack/*[@name=$cpack])"/>                    
                &lt;Field Label="<xsl:value-of select="$metas//Metadatas/*[@typename=$name]/@label"/>" Xpack="<xsl:value-of select="lower-case(@cpack)"/>" XpackType="<xsl:choose><xsl:when test="contains(string($cpackType),'Int')">1</xsl:when><xsl:when test="contains(string($cpackType),'Long')">1</xsl:when><xsl:when test="contains(string($cpackType),'Ratio')">2</xsl:when><xsl:when test="contains(string($cpackType),'Money')">2</xsl:when><xsl:otherwise>3</xsl:otherwise></xsl:choose>" SbpField="<xsl:value-of select="@name"/>"/&gt;</xsl:for-each>
        &lt;/Request&gt;
        </xsl:for-each>
        <xsl:for-each select="Response">&lt;Response&gt;<xsl:for-each select="Field">
                        <xsl:variable name="cpack" select="@cpack"/>
                        <xsl:variable name="name" select="@name"/>
                        <xsl:variable name="cpackType" select="fn:node-name($cpacks//Cpack/*[@name=$cpack])"/>
                &lt;Field Label="<xsl:value-of select="$metas//Metadatas/*[@typename=$name]/@label"/>" Xpack="<xsl:value-of select="lower-case(@cpack)"/>" XpackType="<xsl:choose><xsl:when test="contains(string($cpackType),'Int')">1</xsl:when><xsl:when test="contains(string($cpackType),'Long')">1</xsl:when><xsl:when test="contains(string($cpackType),'Ratio')">2</xsl:when><xsl:when test="contains(string($cpackType),'Money')">2</xsl:when><xsl:otherwise>3</xsl:otherwise></xsl:choose>" SbpField="<xsl:value-of select="@name"/>"/&gt;</xsl:for-each>
        &lt;/Response&gt;</xsl:for-each>&lt;/ProtocolMap&gt;               
	</xsl:for-each>
&lt;/ProtocolMaps&gt;&lt;/ProtocolContent&gt;
	</xsl:result-document>
	</xsl:template>  
</xsl:stylesheet>